<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>模板信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
 <div class="Wrapper">
        <div>
           <div id="pageInTab" class="pageInTab">
		   <div tabid="tabA" title="模板信息" lselected="true">
		<form id="sys_scoretmpl_info_form" >
             <div class="fieldset1 tabel_col clearFix">
                <div class="fieldBox col_50">
                    <div class="label">模板编号</div>
                    <div class="field">
                        <input id="tmplCd" name="tmplCd" type="text"  class="ui-textbox"  value="${tmplCd}"  validate="{required:true}" />
                        <span class="requiredSymbol">*</span>
                    </div>
             </div>
 <div class="fieldBox col_50">
                    <div class="label">模板名称</div>
                    <div class="field">
                        <input id="tmplNm" name="tmplNm" type="text"  class="ui-textbox"  value="${tmplNm}"  validate="{required:true}" />
                        <span class="requiredSymbol">*</span>
                    </div>
             </div>
                
		 <div class="fieldBox col_50">
                <div class="label">所属机构</div>
                <div class="field">
                    <input name="orgCd" id="orgCd" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">评分常量</div>
                 <div class="field">
                        <input id="cons" name="cons" type="text"  class="ui-textbox"  value="${cons}"  validate="{number:true}" />
                        <span class="requiredSymbol">*</span>
                        </div>
            </div>
 </div>
            <!-- hide data -->
	        <div class="fieldBox col_100" style="display:none;">
	          <div class="field">
	                <input name="tmplId" id="tmplId" type="hidden" class="ui-textbox" value="${tmplId}">

	          </div>
	        </div>
	         
            <div class="btnsBox">
               <span id="saveScoreImplInfoBtn" class="sq-button sq-button-round" onclick="saveScoreTmplInfo()"><!-- <i class="sqBtnIco_10"></i> -->保存</span>
               <span id="cancelBtn" class="sq-button sq-button-round" onclick="cancelBtn()"><!-- <i class="sqBtnIco_14"></i> -->取消</span>
            </div>
        </form>
        </div>
              <div tabid="tabB" title="模板指标" id="tabEId" style="display: none;">
                    <iframe frameborder="0" name="tabE" id="tabE" src=""></iframe>
             </div>
        </div>
        </div>
    </div>
    
	<script type="text/javascript">
	  var pageInApp={
	    		flag:true
	    };
	  var tmplid ='${tmplId}';
	  var selectOrgCd = "";
	   var searchOrgTree = null;
	  var firstNode = null;
	  var textName='${orgTextName}';//节点名称
	  var orgData = null;
		var id ="";//初始值
		var detailFlag = '${detailFlag}';
		var isFlow = '${isFlow}';
$(function () {
	initData();
});
	//初始化数据
	function initData(){
			initOrgTree();
		
		 initTab();
			$("#sys_scoretmpl_info_form").ligerForm({
			    validate: true
			});
			 var ligerForm = liger.get("sys_scoretmpl_info_form");
		 $("#sys_scoretmpl_info_form").check_ligerFormEditor();
		
		/*  // 设置业务种类默认为禁用
		    var slt=liger.get("loanTypCd");
            slt.setDisabled();
 */
	
		
		
	
		
	}
	var pageInTab = null;
	  var loadedTabs=[]
	  //获取当前组织机构及其父级节点名称
		
	
	  

	  
    function initOrgTree(){
    	var params = {};
    	 searchOrgTree = $("#orgCd").ligerComboBox({
             selectBoxWidth: 240,
             selectBoxHeight: 150,
             //限制只能选叶节点，父节点不能点击
             treeLeafOnly: false,
             valueField: 'orgCd',
             textField: 'orgDispNm',
             showTreePath: true,
             initValue:'${orgCd}',
             initText:'${orgNm}',
             tree: {
                 ajaxType: 'get',
                 idFieldName:'orgCd',
                 textFieldName: 'orgDispNm',
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none",
                 needCancel : false,
             },
             onSelected: function ()
             {
                /* if(searchOrgTree.treeManager.getSelected()){
    	        	 var orgCd = searchOrgTree.treeManager.getSelected().data['orgCd'];
    	 	         if(orgCd){
    	 	        	 //设置所属客户经理信息
    	 	        	setActManager(orgCd,cstMgrId)
    	 	         }
    	         }*/
             }
         });
    	 $.ajax({
     		type: 'get',
     		dataType:'json',
     		data: params,
     		url: '<%=path%>/system/sysscoretmpl/searchOrgTree.do',
     		success:function(msg){
     			if(msg.success == 1){
     				searchOrgTree.treeManager.setData(msg.data);
     				searchOrgTree.clear();
     				searchOrgTree.setValue('${currOrg}');
     			}else{
     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     			}
     		}
     	});
    	 
    }
    var  searchPrjIndTree = null;
   
    
    
    
    

 	
 	
	
	
	//初始化Tab
    function initTab(){
    	 pageInTab = $("#pageInTab").ligerTab({
             height: 'auto',
             contextmenu: false,
             minIframeHeight: GET_minIframeHeight(),
             onBeforeSelectTabItem: function (tabid) {
             	var tmplId = $("#tmplId").val();
             		//alert("id="+tmplId);
             	 if(tabid!="tabA"){
 	             	if(tmplId==null||tmplId==''){
 	                	top.$.ligerDialog.SQalert({content:"请先保存模板信息", SQ_type: "warning"});
 	                	return false;
 	                } 
             	} 
             },
             onAfterSelectTabItem: function(tabid) {
              //   if (loadedTabs.indexOf(tabid)<0) {
                 	var tmplId = $("#tmplId").val();
                 	//alert("tmplId="+tmplId);
                 	 if(tabid!="tabA"){
 	                	if(tmplId==null||tmplId==''){
 	                		 top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ__PRD_SELECT_BEFORE, SQ_type: "warning"});
 	                         return false; //验证不通过，不执行以下代码
 	                	}
                 	} 
                     loadedTabs.push(tabid);
                     switch (tabid){
                         case "tabB":
                             pageInTab.setTabItemSrc(tabid, "<%=path%>/system/sysscoretmpl/toSysscoreIdxListPage.do?tmplId="+tmplId+"&&detailFlag="+detailFlag);
                             break;
                        
                             
                     }
            //     };
                 SetIframe_height();
             }
         });

         $.extend(true, pageInApp, {
             pageInTab: pageInTab
         });
    };
	//保存模板基础信息
	function saveScoreTmplInfo(){
        var ligerForm = liger.get("sys_scoretmpl_info_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }

     
		var tmplNm = $("#tmplNm").val();
		   var url = '<%=path%>/system/sysscoretmpl/checktmplNm.do';
		    var params = {};
			  params.tmplNm = tmplNm;//模板名称
	        $.ajax({
	    		type: 'post',
	    		dataType:'json',
	    		data:params,
	    		url: url,
	    		success:function(msg){
	    			 if(msg.success == 1){
	    				 top.$.ligerDialog.SQalert({content: "该模板已经存在！",SQ_type: "error"});
	    				 return false;
	    			 }else{
	    				  var data = ligerForm.getData();
	    			       data["tmplId"]=$("#tmplId").val();
	    			      // data["orgCd"]=$("#orgCd").val();
	    			       if(data["orgCd"]==""){
	    			       data["orgCd"]='${orgCd}';
	    			       }
	    			        var url = '<%=path%>/system/sysscoretmpl/Tmpladd.do';
	    			       // var tmplId = $("#tmplId").val();
	    			       // data["tmplId"]= tmplId;
	    			        var wait_dialog;
	    			        $.ajax({
	    			    		type: 'post',
	    			    		dataType:'json',
	    			    		data:data,
	    			    		url: url,
	    			    		beforeSend: function(){
	    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	    					     },
	    			    		success:function(msg){
	    			    					 wait_dialog.close();
	    			    			 if(msg.success == 1){
	    			    					 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    			    				 /*   var TAB=top.mainApp.parentTab;
	    			    			            var currentTabid=TAB.getSelectedTabItemID();
	    			    			            var currFrameElement=top.$("#"+currentTabid).get(0);
	    			    						 var callback=currFrameElement.W2W.callback;
	    						          	  		callback();
	    						          	 	 top.tab.removeTabItem(currentTabid);  */
	    						          	 	$("#tmplId").val(msg.data);
	    						          	 	pageInApp.flag=false;
	    			    			 }else{
	    			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			    			 }
	    			    		}
	    			    	});
	    			 }
	    		}
	    	});
     	
     	
	}
	//取消
	function cancelBtn(){
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();
		 top.tab.removeTabItem(currentTabid);
	}
	
	
    </script>

</body>
</html>